{% extends "layouts/layout.html" %}
{% block title %}
View Item
{% endblock %}
{% block content %}
<script type="text/javascript" src="/js/items/items.js"></script>
<h3>View Item</h3>

{% if item_contents %}
{% if user %}
<h5>Rate this seller:</h5>
<div id="seller_rating"></div>
<script type="text/javascript">
$('#seller_rating').raty({
	score : 3 ,
	click: function(score, evt) {
		if(score > 5){
			score = 5;
		}else if(score < 0){
			score = 0;
		}
		var redir = $('#redirect').text() + score;
		if(confirm('Are you sure you want to give a rating of ' + score + ' to this seller?'))
		window.location = redir;
	}
});
</script>
<div id="redirect" class="hide">/users/submit_foreign_user_feedback?partner_id={{partner_id}}&target_user_id={{item_contents['seller']['id']}}&amp;xsrf_token={{xsrf_token}}&amp;rating=</div><br/>
{% endif %}
<div class="well">
	<p>
		Posted by: {{ escape(item_contents["seller"]["username"]) }}
	</p>
	<p>Title: {{ sanitizeHTML('<a href="' + item_contents["url"] + '">' + item_contents["title"] + '</a>')}} </p>
	<p>Description: <textarea class="readonlyRichText">{{ item_contents["description"] }}</textarea></p>
	<p>Price: ${{ item_contents["price"]}}</p>
  {% if item_contents['image'] %}
    <p>{{ sanitizeHTML('<img src="' + item_contents["image"] + '" />') }}</p>
  {% endif %}
</div>
<p>
	{% if current_li %} {{ sanitizeHTML('<a id="this_is_dumb" href="/threads/new_remote_thread?about=' + item_id + '&item_title=' + item_contents["title"] + '&partner_id=' + partner_id + '&remote_user_id=' + seller_id + '&remote_username=' + seller_name + '">Contact Seller</a>') }}
	<script type="text/javascript">
		$(document).ready(function(){ $("a#this_is_dumb").addClass("btn"); });
	</script>
	{% endif %}
	<a href="/items/" class="btn">Back</a>
</p>
{% if user %}
<p>
	<form action="/items/submit_foreign_feedback" method="post">
		<input type="hidden" name="item_id" value="{{item_contents['id']}}"/>
		<input type="hidden" name="xsrf_token" value="{{xsrf_token}}"/>
    <input type="hidden" name="rating" id="rating" value="3" />
    <input type="hidden" name="partner_id" value="{{ partner_id }}" />
		<div class="well">
			<h4>Are you the buyer? Leave your feedback here:</h4>
			<table>
				<tr>
					<td><textarea name="feedback"></textarea></td>
					<td>Rating:</td>
					<td><div id="rating_div"></div></td>
				</tr>
			</table>
			<button type="submit" class="btn" value="submit">Submit feedback</button>
		</div>
	</form>
</p>
{% endif %}
{% else %}
<div class="alert">
  <strong>Uh oh!</strong> This trusted application does not properly support /webservices/item
</div>
{% endif %}
{% endblock %}